#include <IceUtil/IceUtil.h>
#include "coordinationMiddleware.h"

namespace Collaboration {

EventHandler* EVENT_HANDLER; //definicion de la variable extern event_handler
::Ice::CommunicatorPtr comm;

bool initCoordinationMiddleware()
{
	try{
		comm = Ice::initialize();
		EVENT_HANDLER = new EventHandler(comm, "localhost");
	}catch(const Ice::Exception& e)
	{
		std::cerr << e << std::endl;
		return false;
	}
	catch(const char* msg)
	{
		std::cerr << msg << std::endl;
		return false;
	}
	
	return true;
}

bool initCoordinationMiddleware(const std::string& host)
{
	try{
		comm = Ice::initialize();
		EVENT_HANDLER = new EventHandler(comm, host);
	}catch(const Ice::Exception& e)
	{
		std::cerr << e << std::endl;
		return false;
	}
	catch(const char* msg)
	{
		std::cerr << msg << std::endl;
		return false;
	}
	
	return true;
}

void shutdownCoordinationMiddleware()
{
	delete EVENT_HANDLER;
	
	comm->shutdown();
}

}